//@flow

/**
 * 关于数据库的操作
 */

import launchRecordTB from "./schemes/v1/launchRecordTB";
import RNFS from "react-native-fs";
import Realm,{Configuration} from "realm";
import {Schemes } from "./schemes/schemes";
import * as Config from "../config/config";

//获取当前数据库版本
let currentVersion : number ;

try {
    currentVersion= Realm.schemaVersion(Config.REALM_PATH);
    //如果本地数据库，并非最新的数据，则执行线性更新,
    while(currentVersion<Schemes.length){
        const tmpRealmForMigration = new Realm(Schemes[currentVersion++]);
        tmpRealmForMigration.close()
    }
} catch (error) {
    console.log(`线性迁移出现异常:${JSON.stringify(error)}`)
}
//处理完成，就可以直接打开最新的数据库了
export let realm : Realm = new Realm(Schemes[Schemes.length-1]);